package com.cheguo.zeus.biz.join.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.cheguo.zeus.biz.join.dao.JoinCarDealerContractViewDao;
import com.cheguo.zeus.biz.join.entity.JoinCarDealerContractView;
import com.cheguo.zeus.biz.join.service.JoinCarDealerContractViewService;
import com.cheguo.zeus.join.response.JoinCarDealerContractViewResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 加盟车商信息导出表 服务实现类
 * </p>
 *
 * @author zdf
 * @since 2018-05-28
 */
@Service
public class JoinCarDealerContractViewServiceImpl extends ServiceImpl<JoinCarDealerContractViewDao, JoinCarDealerContractView> implements JoinCarDealerContractViewService {



    @Autowired
    private JoinCarDealerContractViewDao joinCarDealerContractViewDao;


    private static Logger LOG = LoggerFactory.getLogger(JoinCarDealerContractViewServiceImpl.class);


    @Override
    public List<JoinCarDealerContractViewResponse> getDealerAndContractInfo(JoinCarDealerContractView joinCarDealerContractView) {

        try {

            LOG.info("向数据库查询获取车商与合同信息的参数为:{}", JSON.toJSONString(joinCarDealerContractView));

            //数据库查询车商与合同信息
            List<JoinCarDealerContractView> dealerAndContractInfoList = joinCarDealerContractViewDao.queryDealerAndDealerInfo(joinCarDealerContractView);

            //结果判断
            if (null == dealerAndContractInfoList || dealerAndContractInfoList.size() <= 0) {
                LOG.error("未有匹配的查询数据,查询参数为:{}", JSON.toJSONString(joinCarDealerContractView));
                return null;
            }

            //结果类型转换 JoinCarDealerContractView --> JoinCarDealerContractViewResponse
            List<JoinCarDealerContractViewResponse> resultList = new ArrayList<>();
            for (JoinCarDealerContractView joinCarDealerContractView1 : dealerAndContractInfoList) {
                JoinCarDealerContractViewResponse joinCarDealerContractViewResponse = new JoinCarDealerContractViewResponse();
                BeanUtils.copyProperties(joinCarDealerContractView1, joinCarDealerContractViewResponse);
                resultList.add(joinCarDealerContractViewResponse);
            }
            return resultList;
        } catch (Exception e) {
            LOG.error("获取车商与合同信息异常,异常信息为:{}",e);
            return null;
        }
    }


}
